import request from '@/utils/request'
import { Student, StudentFilter, PaginationParams, PaginationResult } from '@/types'

/**
 * 获取学生列表
 */
export function getStudentList(params: PaginationParams & StudentFilter) {
  return request<PaginationResult<Student>>({
    url: '/students',
    method: 'get',
    params
  })
}

/**
 * 获取学生详情
 */
export function getStudentDetail(id: number) {
  return request<Student>({
    url: `/students/${id}`,
    method: 'get'
  })
}

/**
 * 创建学生
 */
export function createStudent(data: Partial<Student>) {
  return request<Student>({
    url: '/students',
    method: 'post',
    data
  })
}

/**
 * 更新学生信息
 */
export function updateStudent(id: number, data: Partial<Student>) {
  return request<Student>({
    url: `/students/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除学生
 */
export function deleteStudent(id: number) {
  return request({
    url: `/students/${id}`,
    method: 'delete'
  })
}

/**
 * 批量导入学生
 */
export function importStudents(data: Partial<Student>[]) {
  return request({
    url: '/students/import',
    method: 'post',
    data: { students: data }
  })
}

/**
 * 导出学生数据 (基础导出)
 */
export function exportStudents(params: StudentFilter) {
  return request<Student[]>({
    url: '/students/export',
    method: 'get',
    params
  })
}

/**
 * 导出学生数据为Excel文件 (基础导出)
 */
export function exportStudentsToExcel(params: StudentFilter) {
  return request({
    url: '/students/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

/**
 * 导出学生详细数据为Excel文件 (详细导出)
 */
export function exportStudentsDetailedToExcel(params: StudentFilter) {
  return request({
    url: '/students/export',
    method: 'get',
    params: {
      ...params,
      type: 'detailed'
    },
    responseType: 'blob'
  })
}

/**
 * 获取专业列表
 */
export function getMajors() {
  return request<string[]>({
    url: '/students/majors',
    method: 'get'
  })
}

/**
 * 获取班级列表
 */
export function getClasses(major?: string) {
  return request<string[]>({
    url: '/students/classes',
    method: 'get',
    params: { major }
  })
}

